package com.ruoyi.operation.cmdb;

/**
 * @Author Zzneko
 * @Date 2025/6/16 13:34
 * @Descprition
 **/

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.util.List;
import java.util.Map;

@Component
@RefreshScope
public class CmdbConcurrenHelper {

    @Value("${cmdb.url:https://cmdb.veops.cn/api/v0.1/ci/s}")
    private String cmdbUrl;

    @Value("${cmdb.key:2d029fc1df6f405abbf64ac0a82de3d7}")
    private String key;

    @Value("${cmdb.secret:L*EP2mW!5q1aw~s^zVKMupv9XQ$tHhJT}")
    private String secret;


    /**
     * 同步DMDB接口。Get方法
     * @param signParams
     * @return
     */
    public List<Map<String,String>> getCMDBData(Map<String,Object> signParams){
        URI uri = URI.create(cmdbUrl);
        String path = uri.getPath();
        //鉴权
        Map<String,Object> signedParams = CmdbUtils.buildApiKey(path,signParams,key,secret);
        String queryParamStr = CmdbUtils.buildQueryStr(signedParams);
        String string = HttpUtil.get(cmdbUrl + "?" + queryParamStr);
        JSONObject object = JSON.parseObject(string);
        return ((List<Map<String,String>>) object.get("result"));
    }
}
